home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 September / macformat-004.iso / Shareware City / Games / Jotto ][ 1.1.source Folder / MyMDEF ƒ / my mdef.c next >
Encoding:
C/C++ Source or Header  |  1994-07-06  |  2.1 KB  |  80 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        my mdef.c
  4.  
  5. Purpose:    This module handles an MDEF for an on-the-fly Sierpinski's
  6.             Gasket.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. /* compile as code resource, type 'MDEF', ID 1234, attributes = 0x00 */
  26. /* no custom header, file type 'rsrc', creator 'RSED' */
  27. /* compile & merge into project .rsrc file */
  28. /* set MDEF ID of the menu to 1234 with Resedit */
  29.  
  30. #include "SetUpA4.h"
  31.  
  32. #define MENU_WIDTH 256
  33. #define MENU_HEIGHT 222
  34.  
  35. pascal void main(short message, MenuHandle theMenu, Rect *r, Point hitPt, short *which);
  36.  
  37. short        curX=0;
  38. short        curY=0;
  39.  
  40. pascal void main(short message, MenuHandle theMenu, Rect *r, Point hitPt, short *which)
  41. {
  42.     Point            pt;
  43.     short            whichVertex;
  44.     short            newX, newY;
  45.     
  46.     RememberA0();
  47.     SetUpA4();
  48.     switch (message)
  49.     {
  50.         case 0:
  51.             /* draw the menu */
  52.             EraseRect(r);
  53.             break;
  54.         case 1:
  55.             /* choose and hilight */
  56.             whichVertex=(Random()&0x7fff)%3;
  57.             switch (whichVertex)
  58.             {
  59.                 case 0:    SetPt(&pt, MENU_WIDTH/2, 0);            break;
  60.                 case 1:    SetPt(&pt, 0, MENU_HEIGHT);                break;
  61.                 case 2:    SetPt(&pt, MENU_WIDTH, MENU_HEIGHT);    break;
  62.             }
  63.             newX=((pt.h)+curX)/2;
  64.             newY=((pt.v)+curY)/2;
  65.             MoveTo(r->left+newX, r->top+newY);
  66.             Line(0,0);
  67.             curX=newX;
  68.             curY=newY;
  69.             break;
  70.         case 2:
  71.             /* calculate size */
  72.             (**theMenu).menuWidth = MENU_WIDTH;
  73.             (**theMenu).menuHeight = MENU_HEIGHT;
  74.             curX=MENU_WIDTH/2;
  75.             curY=0;
  76.             break;
  77.     }
  78.     RestoreA4();
  79. }
  80.